<?php

use think\migration\Seeder;

class AirQualityWeatherForecastRealtimeHourData extends Seeder
{

    public function run()
    {
        $table = $this->table('air_quality_weather_realtime_hour');

        $rows = [];
        $i    = 0;
        $num  = 168;
        while ($num > 0) {
            //step1:风向
            $typeArr    = ['东风', '西风', '南风', '北风'];
            $randomKeys = array_rand($typeArr);

            //step2:总云量对应的天气名称及图标
            $skyCondition     = '';
            $skyConditionIcon = '';
            $cloudCover       = mt_rand(0, 100);
            if ($cloudCover >= 0 && $cloudCover < 30) {
                $skyCondition     = '晴';
                $skyConditionIcon = 'icon-qing';
            }
            if ($cloudCover >= 30 && $cloudCover < 60) {
                $skyCondition     = '少云';
                $skyConditionIcon = 'icon-tianqi2';
            }
            if ($cloudCover >= 60 && $cloudCover < 90) {
                $skyCondition     = '多云';
                $skyConditionIcon = 'icon-tianqizitiku02';
            }
            if ($cloudCover >= 90 && $cloudCover <= 100) {
                $skyCondition     = '阴';
                $skyConditionIcon = 'icon-yintian';
            }

            //step3:插入的数组
            $rows[] = [
                //step1:地区
                'region_id'          => 53,

                //step2:时间
                'publish_time'       => date('Y-m-d H', time() - 3600 * $i) . ':00:00',   //发布时间-1个小时一条，1天24小时，这里计算从现在开始的24小时内
                'create_time'        => date('Y-m-d H:i:s', time()),          //插入时间

                //step3:天气六参
                'surface_temp'       => mt_rand(-20, 20),         //气温
                'surface_wind'       => mt_rand(1, 12),           //风力
                'wind_dir'           => $typeArr[$randomKeys],     //风向
                'rh'                 => mt_rand(0, 100),          //相对湿度
                //总云量及相关天气
                'cloud_cover'        => $cloudCover,          //总云量
                'sky_condition'      => $skyCondition,          //总云量对应的天空情况
                'sky_condition_icon' => $skyConditionIcon,          //总云量对应的天空情况对应的图标
                'pressure'           => mt_rand(500, 1000),       //气压
            ];
            $num--;
            $i++;
        }

        $table->insert($rows)->save();
    }
}